package org.shopping.web.commodity;

import org.shopping.domain.Commodity;
import org.shopping.service.commodity.CommodityService;
import org.shopping.service.commodity.impl.CommodityServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ShowCommodityController", value = "/ShowCommodityController",loadOnStartup = 2)
public class ShowCommodityController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 创建业务层对象
        CommodityService service = new CommodityServiceImpl();
        // 调用业务层查询所有方法,保存到域对象,转发到显示所有商品的首页
        List<Commodity> lists = service.selectAll();
        request.setAttribute("list", lists);
        request.getRequestDispatcher("/index.jsp").forward(request, response);
    }
}
